package com.xydtech.workflow.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.workflow.domain.WflFlowstep;
import com.xydtech.workflow.domain.WflStepskip;
import com.xydtech.workflow.service.IWflFlowstepService;
import com.xydtech.workflow.service.IWflStepskipService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 流程节点跳过条件配置Controller
 *
 * @author JHON
 * @date 2021-06-02
 */
@Controller
@RequestMapping("/workflow/stepskip")
public class WflStepskipController extends BaseController {
    private String prefix = "workflow/stepskip";

    @Autowired
    private IWflStepskipService wflStepskipService;
    @Autowired
    private IWflFlowstepService wflFlowstepService;

    /**
     * 新增流程节点跳过条件配置
     */
    @GetMapping("/add/{versionId}/{orderNum}")
    public String add(@PathVariable("versionId") Long versionId, @PathVariable("orderNum") Long orderNum, ModelMap mmap) {
        //查询流程节点信息
        WflFlowstep wflFlowstep = wflFlowstepService.selectWflFlowstepByVersionIdAndOrderNum(versionId, orderNum);
        mmap.put("versionId", versionId);
        mmap.put("stepId", wflFlowstep.getStepId());
        return prefix + "/add";
    }

    /**
     * 新增保存流程节点跳过条件配置
     */
    @RequiresPermissions("workflow:flowdefine:add")
    @Log(title = "流程节点跳过条件配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WflStepskip wflStepskip) {
        return toAjax(wflStepskipService.insertWflStepskip(wflStepskip));
    }

    /**
     * 修改流程节点跳过条件配置
     */
    @GetMapping("/edit/{conditionId}")
    public String edit(@PathVariable("conditionId") Long conditionId, ModelMap mmap) {
        WflStepskip wflStepskip = wflStepskipService.selectWflStepskipById(conditionId);
        mmap.put("wflStepskip", wflStepskip);
        return prefix + "/edit";
    }

    /**
     * 修改保存流程节点跳过条件配置
     */
    @RequiresPermissions("workflow:flowdefine:edit")
    @Log(title = "流程节点跳过条件配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WflStepskip wflStepskip) {
        return toAjax(wflStepskipService.updateWflStepskip(wflStepskip));
    }

    /**
     * 删除流程节点跳过条件配置
     */
    @RequiresPermissions("workflow:flowdefine:remove")
    @Log(title = "流程节点跳过条件配置", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(wflStepskipService.deleteWflStepskipByIds(ids));
    }
}
